package cn.supermarket.controller;


import cn.supermarket.pojo.dto.AddProductInputDTO;
import cn.supermarket.pojo.dto.UpdateProductInputDTO;
import cn.supermarket.pojo.vo.ProductInputVO;
import cn.supermarket.service.iservice.IPmsInboundService;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 入库单 前端控制器
 * </p>
 *
 * @author the shy
 * @since 2022-07-14
 */
@RestController
@RequestMapping("/Inbound")
@Api(tags = "入库")
public class PmsInboundController extends BaseController {

    @Autowired
    private IPmsInboundService pmsInboundService;


    @PostMapping("/add")
    @ApiOperation("添加入库记录")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "单位", name = "company", required = true, dataType = "String",example = "吨"),
            @ApiImplicitParam(value = "供货商", name = "supplier", required = true, dataType = "String",example = "张泽泽"),
            @ApiImplicitParam(value = "时间", name = "date", required = true, dataType = "Date",example = "2022-07-06"),
            @ApiImplicitParam(value = "操作人员", name = "consignee", required = true, dataType = "String",example = "admin001"),
            @ApiImplicitParam(value = "商品id", name = "productId", required = true, dataType = "Long",example = "457821457"),
            @ApiImplicitParam(value = "数量", name = "quantity", required = true, dataType = "BigDecimal",example = "500"),
            @ApiImplicitParam(value = "备注", name = "remarks", dataType = "String",example = "备注")
    })
    public JsonResult addOutboundRecord(AddProductInputDTO productInput) {
        pmsInboundService.addInboundRecord(productInput);
        return JsonResult.ok("添加完成!");
    }

    @PostMapping("/update")
    @ApiOperation("修改入库信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "入库单号", name = "deliveryOrderNo", required = true, dataType = "Long",example = "994369590173630464"),
            @ApiImplicitParam(value = "供货商", name = "supplier",  dataType = "String",example = "张泽泽"),
            @ApiImplicitParam(value = "操作人员", name = "operator", dataType = "String",example = "admin001"),
            @ApiImplicitParam(value = "商品id", name = "productId", dataType = "Long", example = "21457214"),
            @ApiImplicitParam(value = "数量", name = "quantity",  dataType = "BigDecimal",example = "500"),
            @ApiImplicitParam(value = "备注", name = "remarks", dataType = "String",example = "备注"),
            @ApiImplicitParam(value = "是否作废,0=未作废,1=作废", name = "isCancel", dataType = "Integer",example = "0"),
            @ApiImplicitParam(value = "是否可见,0=隐藏,1=可见", name = "isDisplay",  dataType = "Integer",example = "1"),
            @ApiImplicitParam(value = "是否锁定,0=未锁定,1=锁定", name = "isEnable",  dataType = "Integer",example = "0"),
            @ApiImplicitParam(value = "时间", name = "date",  dataType = "Date",example = "2202-07-07"),
    })
    public JsonResult updateInfo(UpdateProductInputDTO updateProductInputDTO) {
        pmsInboundService.updateInfo(updateProductInputDTO);
        return JsonResult.ok("修改完成!");
    }

    @GetMapping("/get/inOrderNo/{inOrderNo}")
    @ApiOperation("按照出库单号查询信息")
    @ApiImplicitParam(value = "出库单号", name = "inOrderNo", required = true, dataType = "Long",example = "1")
    public JsonResult<List<ProductInputVO>> getListByInOrderNo(@PathVariable("inOrderNo") Long inOrderNo) {
        List<ProductInputVO> list = pmsInboundService.getListByInOrderNo(inOrderNo);
        return JsonResult.ok(list);
    }

    @GetMapping("/get/date/{date}")
    @ApiOperation("按照日期查询信息")
    @ApiImplicitParam(value = "日期", name = "date", required = true, dataType = "Date",example = "2022-07-06")
    public JsonResult<List<ProductInputVO>> getListByDate(@PathVariable("date") Date date) {
        List<ProductInputVO> list = pmsInboundService.getListByDate(date);
        return JsonResult.ok(list);
    }


}
